package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.EepMapperJob;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.EmpServiceJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * CTassName: EmpServiceImplJob
 * Package: com.itheima.service.impl
 * Description:
 *
 * @Author xw
 * @Create 2023/11/4 22:01
 * @Version 1.0
 */

@Service
public class EmpServiceImplJob implements EmpServiceJob {

    @Autowired
    private EepMapperJob empMapper;

    // 分页
    @Override
    public PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {


        // 设置分页参数
        PageHelper.startPage(page, pageSize);



        //执行条件分页查询
        List<Emp> empList = empMapper.page(name, gender, begin, end);

        // 获取分页结果
        Page<Emp> p = (Page<Emp>) empList;


        //封装PageBean
        return new PageBean(p.getTotal(), p.getResult());

    }

    // 添加
    @Override
    public void add(Emp emp) {
        empMapper.add(emp);
    }


    // 删除
    @Override
    public void deleteEmp(String[] idArray) {
        empMapper.deleteEmp(idArray);
    }


    // 修改
    @Override
    public Emp getById(Integer id) {
        return empMapper.findById(id);
    }

    // 修改
    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now()); //更新修改时间为当前时间
        empMapper.update(emp);
    }
}
